package list.utils;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @Author Administrator
 * @Date 2020/6/12 10:23
 * JDBC工具类，获取数据库连接等操作
 **/
public class JDBCUtils {
    private static DataSource ds;
    static {
        /*加载配置文件进内存
        * 初始化ds*/
       try{
           Properties pro = new Properties();
           pro.load(JDBCUtils.class.getClassLoader().getResourceAsStream("druid.properties"));
          ds = DruidDataSourceFactory.createDataSource(pro);
       } catch (Exception e) {
           e.printStackTrace();
       }
    }
    public static DataSource getDataSource(){
        return ds;
    }
    public static Connection getConnection() throws SQLException{
        return ds.getConnection();
    }
}
